package com.guaju.yueshangLife.activity.mine;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.annotation.MainThread;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.base.BaseActivity;
import com.guaju.yueshangLife.bean.AboutUsBean;
import com.guaju.yueshangLife.bean.HomeTotal;
import com.guaju.yueshangLife.databinding.ActivityAboutBinding;
import com.guaju.yueshangLife.net.ApiEntity;
import com.guaju.yueshangLife.utils.ToastUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class AboutActivity extends BaseActivity {

    ActivityAboutBinding binding;
    private String service_agreement;

    @Override
    protected void loadViewLayout() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_about);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void bindViews() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        ApiEntity.aboutUs();

    }

    @Override
    protected void setListener() {
        binding.rlGoInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AboutActivity.this, AboutInfoActivity.class);
                intent.putExtra(AboutInfoActivity.INFO,service_agreement);
                startActivity(intent);
            }
        });

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onAbout(AboutUsBean data) {
        if (data!=null){
            AboutUsBean.DataBean data1 = data.getData();
            if (data1!=null){
                String phone = data1.getPhone();
                String email = data1.getEmail();
                service_agreement = data1.getService_agreement();
                binding.tvTel.setText(phone);
                binding.tvEmail.setText(email);
            }else{
                ToastUtil.show("获取数据错误,请稍后重试");
                finish();
            }
        }else{
            ToastUtil.show("获取数据错误,请稍后重试");
            finish();
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
